Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuData: ["钢琴", "柜子", "梳妆台", "床", "沙发", "桌子", "冰箱", "空调", "洗衣机", "电视机"],
    menuClass: '',
    tabIndex: 0,
    qtyArr: [[0, 0, 0, 0, 0], [0, 0, 0], [0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0, 0, 0], [0, 0], [0, 0, 0, 0]],
    total: 0,
    qty:0,
    numBoxList: [
      {
        "list": [
          {
            "des": "120以下含120",
            "price": 230,
            "index": 0
          },
          {
            "des": "120以上",
            "price": 280,
            "index": 1
          },
          {
            "des": "125以上",
            "price": 330,
            "index": 2
          },
          {
            "des": "130以上",
            "price": 300,
            "index": 3
          },
          {
            "des": "三角钢琴",
            "price": 600,
            "index": 4
          }
        ]
      },
      {
        "list": [
          {
            "des": "二门柜",
            "price": 100,
            "index": 5
          },
          {
            "des": "三门柜",
            "price": 150,
            "index": 6
          },
          {
            "des": "四门柜",
            "price": 200,
            "index": 7
          }
        ]
      },
      {
        "list": [
          {
            "des": "梳妆台",
            "price": 50,
            "index": 8
          }
        ]
      },
      {
        "list": [
          {
            "des": "1.5米以下",
            "price": 50,
            "index": 9
          },
          {
            "des": "1.5米以上",
            "price": 100,
            "index": 10
          },
          {
            "des": "实木床",
            "price": 150,
            "index": 11
          }
        ]
      },
      {
        "list": [
          {
            "des": "单人沙发",
            "price": 50,
            "index": 12
          },
          {
            "des": "双人沙发",
            "price": 80,
            "index": 13
          },
          {
            "des": "组合沙发",
            "price": 150,
            "index": 14
          }
        ]
      },
      {
        "list": [
          {
            "des": "电脑桌/小办公桌/小餐桌 1.5米以下",
            "price": 50,
            "index": 15
          },
          {
            "des": "电脑桌/办公桌/餐桌 1.5米以上",
            "price": 80,
            "index": 16
          },
          {
            "des": "实木桌实木茶几",
            "price": 150,
            "index": 17
          }
        ]
      },
      {
        "list": [
          {
            "des": "单开门或200升以下小冰箱",
            "price": 50,
            "index": 18
          },
          {
            "des": "较大双门或三门冰箱(200-300升)",
            "price": 100,
            "index": 19
          },
          {
            "des": "大型三门及多门冰箱(300升以上)",
            "price": 200,
            "index": 20
          }
        ]
      },
      {
        "list": [
          {
            "des": "1p/1.5p拆装",
            "price": 220,
            "index": 21
          },
          {
            "des": "2p拆装",
            "price": 280,
            "index": 22
          },
          {
            "des": "3p拆装",
            "price": 380,
            "index": 23
          },
          {
            "des": "1.5p一拖二拆装",
            "price": 300,
            "index": 24
          },
          {
            "des": "5p拆装",
            "price": 480,
            "index": 24
          }
        ]
      },
      {
        "list": [
          {
            "des": "小型洗衣机",
            "price": 50,
            "index": 26
          },
          {
            "des": "滚筒洗衣机",
            "price": 150,
            "index": 27
          }
        ]
      },
      {
        "list": [
          {
            "des": "液晶电视(32以下)",
            "price": 30,
            "index": 28
          },
          {
            "des": "液晶电视(32-50以下)",
            "price": 50,
            "index": 29
          },
          {
            "des": "液晶电视(50以上)",
            "price": 80,
            "index": 30
          },
          {
            "des": "背投电视(32以上)",
            "price": 150,
            "index": 31
          }
        ]
      }
    ]
  },
  tabMenu: function (e) {
    console.log(e.target.dataset.index)
    this.setData({
      tabIndex: e.target.dataset.index
    })
  },
  tapNumBox: function (e) {
    var mIdx = e.target.dataset.mindex;
    var sIdx = e.target.dataset.index;
    var type = e.target.dataset.type;
    var qty = this.data.qtyArr[mIdx][sIdx];
    var arr = [];
    var totalPrice = 0;
    var totalQty = 0;
    if (type == 1) {
      if (qty == 0) {
        qty = 0;
      } else {
        qty--
      }
    } else {
      qty++
    };
    for (var i = 0, len = this.data.qtyArr.length; i < len; i++) {
      arr.push(this.data.qtyArr[i])
      for (var k = 0, lens = this.data.qtyArr[i].length; k < lens; k++) {
        if (mIdx == i && sIdx == k) {
          this.data.qtyArr[i][k] = qty;
        }
        totalPrice += this.data.numBoxList[i].list[k].price * this.data.qtyArr[i][k];
        totalQty += this.data.qtyArr[i][k]
      }
    }

    this.setData({
      qtyArr: arr,
      total: totalPrice,
      qty: totalQty
    })

  },
  tabBtnSure: function () {
    var pages = getCurrentPages();
    var prePage = pages[pages.length - 2]
    var self = this;

    prePage.setData({
      wpQty: self.data.qty,
      wpTotalPrice: self.data.total,
    })  
    prePage.calTotal();
    wx.navigateBack({})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})